<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
    x:Class="OpenLS.Spreadsheet.UI.GroupResources"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI"
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.Internals;assembly=OpenLS.Spreadsheet"
    xmlns:Internals1="clr-namespace:OpenLS.Spreadsheet.UI.Internals">

    <Style x:Key="rowStyle">
        <Setter Property="ssui:GroupPanel.ChildOffset" Value="{Binding Path=FirstOffset}"></Setter>
    </Style>
        
    <Style x:Key="groupButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Focusable" Value="false" />
    	<Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border BorderBrush="{DynamicResource {x:Static ssui:SpreadsheetBrushes.GroupLightBackgroundKey}}" BorderThickness="1" Width="16" Height="16" Background="Transparent" >
                        <Grid Background="Transparent" SnapsToDevicePixels="True">
                            <Path StrokeThickness="2" Name="path" Stroke="Black" Data="M 4 0 L4 8 M 0 4 L 8 4" Fill="Black" HorizontalAlignment="Center" VerticalAlignment="Center"></Path>
                            <!--
                            <Line Name="l1" Stroke="Black" StrokeThickness="2" X2="7" HorizontalAlignment="Center" VerticalAlignment="Center"></Line>
                            <Line Name="l2" Stroke="Black" StrokeThickness="2" Y2="7"  HorizontalAlignment="Center" VerticalAlignment="Center"></Line>
                            -->
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding IsExpanded}" Value="True">
                           <!-- <Setter TargetName="l2" Property="Visibility" Value="Hidden" >
                            </Setter>-->
                            <Setter TargetName="path" Property="Data" Value="M 0 4 L 8 4"></Setter>
                        </DataTrigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Focusable" Value="False"></Setter>
        <EventSetter Event="Click" Handler="b_Click"/>
        <Style.Triggers>

        </Style.Triggers>
    </Style>
    <Style TargetType="{x:Type Rectangle}" x:Key="anyRectangle">
        <Setter Property="Fill" Value="Black"></Setter>
    </Style>
    <Style TargetType="{x:Type Rectangle}" x:Key="leftRectangle" BasedOn="{StaticResource anyRectangle}">
        <Setter Property="Width" Value="2"></Setter>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="Margin" Value="4 0 0 0"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
    </Style>

    <Style TargetType="{x:Type Rectangle}" x:Key="topRectangle" BasedOn="{StaticResource anyRectangle}">
        <Setter Property="Height" Value="2"></Setter>
        <Setter Property="VerticalAlignment" Value="Top"/>
        <Setter Property="Margin" Value="0 4 0 0"/>

        <Setter Property="HorizontalAlignment" Value="Stretch"/>
    </Style>
    <DataTemplate DataType="{x:Type Internals:RowGroup}">
        <Grid Height="{Binding TotalHeight}" Background="{DynamicResource {x:Static ssui:SpreadsheetBrushes.GroupBackgroundKey}}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="{Binding Path=First.ActualHeight}" />
                    <RowDefinition />
                    <RowDefinition Height="{Binding Path=Next.ActualHeight}" />
                </Grid.RowDefinitions>
                <Grid Name="line1">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Line Margin ="4 0 0 0 " StrokeThickness="2" X2="8" Stroke="Black" VerticalAlignment="Top"></Line>
                    <Rectangle Style="{StaticResource leftRectangle}"></Rectangle>

                </Grid>
                <Rectangle Style="{StaticResource leftRectangle}" Name="line2" Grid.Row="1" ></Rectangle>
                <Grid Grid.Row="2" Name="grid1">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>

                    </Grid.RowDefinitions>
                    <Rectangle Name="line3" Style="{StaticResource leftRectangle}" Grid.Row="0" ></Rectangle>
                    <Button  Grid.Row="1" Style="{StaticResource groupButtonStyle}" />
                </Grid>
            </Grid>
            <ItemsControl Name="children" Grid.Column="1" ItemContainerStyle="{StaticResource rowStyle}" >
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <ssui:GroupPanel Orientation="Vertical" ContainerOffset="{Binding Path=FirstOffset}"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

            </ItemsControl>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsMeaningful}" Value="False">
                <Setter TargetName="line1" Property="Visibility" Value="Hidden"/>
                <Setter TargetName="line2" Property="Visibility" Value="Hidden"/>
                <Setter TargetName="grid1" Property="Visibility" Value="Hidden"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding IsExpanded}" Value="True">
                <Setter TargetName="children" Property="ItemsSource" Value="{Binding Children}"></Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding IsExpanded}" Value="False">
                <Setter TargetName="line1" Property="Visibility" Value="Collapsed" />
                <Setter TargetName="line2" Property="Visibility" Value="Collapsed" />
                <Setter TargetName="line3" Property="Visibility" Value="Collapsed" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>



    <DataTemplate DataType="{x:Type Internals:ColumnGroup}" >
        <Grid Width="{Binding TotalWidth}" Background="{DynamicResource {x:Static ssui:SpreadsheetBrushes.GroupBackgroundKey}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="{Binding Path=First.ActualWidth}"/>
                    <ColumnDefinition />
                    <ColumnDefinition Width="{Binding Path=Next.ActualWidth}"/>
                </Grid.ColumnDefinitions>
                <Grid Name="line1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <!--<ColumnDefinition/> -->
                    </Grid.ColumnDefinitions>
                    <Line Margin ="0 4 0 0" StrokeThickness="2" Y2="8" Stroke="Black" HorizontalAlignment="Left"></Line>
                    <Rectangle Style ="{StaticResource topRectangle}" ></Rectangle>

                </Grid>
                <Rectangle Name="line2" Grid.Column="1" Style ="{StaticResource topRectangle}" ></Rectangle>
                <Grid Grid.Column="2" Name="grid1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Rectangle Name="line3" Style ="{StaticResource topRectangle}" ></Rectangle>
                    <Button  Grid.Column="1" Style="{StaticResource groupButtonStyle}">
                    </Button>

                </Grid>
            </Grid>
            <ItemsControl Name="children" Grid.Row="1" ItemContainerStyle="{StaticResource rowStyle}" >
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <ssui:GroupPanel Orientation="Horizontal" ContainerOffset="{Binding Path=FirstOffset}"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

            </ItemsControl>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsMeaningful}" Value="False">
                <Setter TargetName="line1" Property="Visibility" Value="Hidden"/>
                <Setter TargetName="line2" Property="Visibility" Value="Hidden"/>
                <Setter TargetName="grid1" Property="Visibility" Value="Hidden"/>
            </DataTrigger>

            <DataTrigger Binding="{Binding IsExpanded}" Value="True">
                <Setter TargetName="children" Property="ItemsSource" Value="{Binding Children}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsExpanded}" Value="False">
                <Setter TargetName="line1" Property="Visibility" Value="Collapsed" />
                <Setter TargetName="line2" Property="Visibility" Value="Collapsed" />
                <Setter TargetName="line3" Property="Visibility" Value="Collapsed" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    <Style TargetType="{x:Type Button}" x:Key="outlineButton">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static ssui:SpreadsheetBrushes.GroupLightBackgroundKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border Width="14" Height="14" BorderBrush="{TemplateBinding Foreground}"  BorderThickness="1" Background="Transparent">
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <EventSetter Event="Click" Handler="outlineButtonClick"></EventSetter>
    </Style>
    <Style TargetType="{x:Type ItemsControl}" x:Key="outlineButtons">
        <Setter Property="Background" Value="{DynamicResource {x:Static ssui:SpreadsheetBrushes.GroupBackgroundKey}}"/>
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Button Style="{StaticResource outlineButton}" Content="{Binding}"></Button>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemsSource">
        <Setter.Value>
            <Binding RelativeSource="{RelativeSource Self}" Path="Tag.MaxDepth">
                <Binding.Converter>
                    <Internals1:IntegerEnumerator/>
                </Binding.Converter>
            </Binding>
        </Setter.Value>
            </Setter>
        <Setter Property="Tag">
            <Setter.Value>
                <Binding ConverterParameter="rows">
                    <Binding.Converter>
                        <Internals1:RootGroupAccessor/>
                    </Binding.Converter>
                </Binding>
            </Setter.Value>
        </Setter>

    </Style>
</ResourceDictionary>